package com.ha8.netease.views.team.statusbar
{
	import com.ha8.netease.PublicNotify;
	import com.rogo.mvc.interfaces.INotification;
	import com.rogo.mvc.sub.mediator.Mediator;
	
	import flash.events.MouseEvent;
	
	public class StatusBarMediator extends Mediator
	{
		public function StatusBarMediator(viewComponent:Object)
		{
			super(NAME, viewComponent);
		}
		
		
		//--------------------------------------------------------------------------
		//
		//  Constants
		//
		//--------------------------------------------------------------------------
		
		public static const NAME:String = 'statusBarMediator';
		
		//--------------------------------------------------------------------------
		//
		//  Overridden Methods
		//
		//--------------------------------------------------------------------------
		
		override public function onRegister():void
		{
			view.setingBtn.addEventListener(MouseEvent.CLICK, createSetingView);
			view.searchBtn.addEventListener(MouseEvent.CLICK, createSearchView);
			view.otherBtn.addEventListener(MouseEvent.CLICK, createSuggestionsView);
		}
		
		override public function listNotificationInterests():Array
		{
			return [PublicNotify.LOGIN_RESULT, PublicNotify.LOGIN_ERROR];
		}
		
		override public function notificationHandler(notification:INotification):void
		{
			switch (notification.name)
			{
				case PublicNotify.LOGIN_RESULT:
					view.currentState = "resultView";
					break;
				case PublicNotify.LOGIN_ERROR:
					view.currentState = "errorView";
					break;
			}
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		public function get view():StatusBar
		{
			return viewComponent as StatusBar;
		}
		
		private function createSearchView(e:MouseEvent):void
		{
			sendNotification(PublicNotify.CREATE_SEARCH_PAGE);
		}
		
		private function createSetingView(e:MouseEvent):void
		{
			sendNotification(PublicNotify.CREATE_PUBLISH_PAGE);
		}
		
		private function createSuggestionsView(e:MouseEvent):void{
			sendNotification(PublicNotify.OPEN_SUGGESTIONS_NOTIFY);
		}
	}
}